package Googol字符串;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for (int cases = 1; cases <= T; cases++) {
            long k = in.nextLong();
            System.out.printf("Case #%d: %d\n", cases, dfs(63, k));
        }
    }

    private static long dfs(int n, long k) {
        long len = (1L << n - 1) - 1;
        if (k <= len) {
            return dfs(n - 1, k);
        }
        if (k == len + 1) {
            return 0;
        }
        return 1 ^ dfs(n - 1, len + 1 - (k - len - 1));
    }
}
